#include "sdlFont.h"

using std::string;

unsigned sdlFont::counter = 0;
sdlTTFMonitor* sdlFont::monitor = NULL;

void sdlFont::init(){
	this->font = NULL;
	if (monitor == NULL){
		monitor = sdlTTFMonitor::getInstance();
	}
	counter++;
}

sdlFont::sdlFont(){
	this->init();
}

sdlFont::sdlFont(string path, unsigned char size){
	this->init();
	this->load(path, size);
}

bool sdlFont::load(std::string path, unsigned char size){
	if (this->font != NULL){
		TTF_CloseFont(this->font);
		this->font = NULL;
	}
	this->font = TTF_OpenFont(path.c_str(), size);
	if (this->font == NULL){return false;}
	return true;
}

TTF_Font* sdlFont::getFont(){
	return this->font;
}

sdlFont::~sdlFont(){
	counter--;
	TTF_CloseFont(this->font);
	if (counter == 0){
		sdlTTFMonitor::eliminar();
		monitor = NULL;
	}
}
